import com.troyworks.tester.ITestRunner;
import com.troyworks.framework.BaseObject;
/**
 * @author Troy Gardner
 */
class com.troyworks.tester.ATest extends BaseObject implements ITestRunner {
	public var testGrader:Function;
	public var description:String;

	public var passed : Boolean;

	public var failedMessage : Object;

	private var name : String;
	public static var EVTD_TESTFINISHED:String = EVTD_TESTFINISHED;
	
	public function ATest(aTest:Function, aName:String, aFailedMessage:String){
		super();
		testGrader = aTest;
		name = aName;
		failedMessage = aFailedMessage;
	}
	public function passedTest():Boolean{
		
		return passed;
	}
	public function startTest() : Void {
		try{
			trace("starting test ");
			passed = testGrader();
		}catch(e:Error){
			passed = false;
		}
		onTestFinished();
	}

	public function onTestFinished() : Boolean {
		trace(name + "ATest.onTestFinishedAAA==========================");
		REQUIRE(passedTest(), failedMessage);
		dispatchEvent({type:EVTD_TESTFINISHED, passed:passed});
		trace(name + "ATest.onTestFinishedBBB==========================");
		
		return passed;
	}
	public function toString():String{
		var res:String = null;
		res = "Test "+ name + " passed?: " + passed;
		return res;
	}
}